<template>
  <el-card class="log">
    <div slot="header" class="title">日志输出</div>
    <div>
      <el-select v-model="selectedId">
        <div slot="prefix" class="select-prefix">
          <div>#</div>
        </div>
        <el-option v-for="quest in quests" :key="quest.id" :value="quest.id">
          <span>#{{ quest.id }}</span>
          <span v-show="quest.status == 3" class="tip-finished">（已结束）</span>
          <span v-show="quest.status != 2 && quest.status != 3" class="tip-failed">（失败）</span>
        </el-option>
      </el-select>
    </div>
    <p v-if="selectedId != null" class="output">{{ logs[selectedId] }}</p>
  </el-card>
</template>

<script>
export default {
  props: {
    logs: Object,
    queue: Array
  },
  data() {
    return {
      selectedId: null
    }
  },
  computed: {
    quests() {
      const rt = []
      for (const id in this.logs) {
        const quest = this.queue.find(q => q.id == id)
        if (quest) {
          rt.push(quest)
        }
      }
      return rt
    }
  },
  methods: {
    changeSelected(id) {
      if (this.logs[id] != null) {
        this.selectedId = id
      }
    }
  }
}
</script>

<style scoped>
.tip-finished,
.tip-failed {
  margin-left: 5px;
  font-weight: bold;
  font-size: 12px;
}

.tip-finished {
  color: #909399;
}

.tip-failed {
  color: #f56c6c;
}

.output {
  white-space: pre-wrap;
  overflow-wrap: break-word;
}
</style>
